package tools

// 普通类型使用 max()函数即可
func Max[T comparable](compareFunc func(a, b T) bool, value ...T) (result T) {
	if len(value) == 0 {
		return
	}
	var v = value[0]
	for _, t := range value {
		if compareFunc(t, v) {
			v = t
		}
	}
	return v
}

func First[T any](array []T) (first T) {
	if len(array) == 0 {
		return
	}

	return array[0]
}

func Last[T any](array []T) (first T) {
	if len(array) == 0 {
		return
	}

	return array[len(array)-1]
}

func GetTargetValue[T, K, V any](array []T, key K, equalFunc func(T, K) bool, valueCast func(T) V) (v V) {
	for _, item := range array {
		if !equalFunc(item, key) {
			continue
		}
		return valueCast(item)
	}
	return
}
